<template>
	<view class="header">
		<view class="flexbox"
			:style="[{'height': customBarH + 'rpx', 'padding-top': statusBarH + 'rpx', 'color': titleColor, 'background': bgColor}]">
			<view @tap="goBack" v-if="isBack">
				<slot name="back"><u-icon name="arrow-left" color="#000" size="22"></u-icon></slot>
			</view>
			<view style="width: 36px;"></view>
			<view class="title">{{title}}</view>
			<view v-if="isBack" style="width: 36px;"></view>
			<view style="width: 36px;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarH: 0,
				customBarH: 0
			}
		},
		props: {
			title: {
				type: String,
				default: ''
			},
			titleColor: {
				type: String,
				default: '#000'
			},
			bgColor: {
				type: String,
				default: '#f8f8f8'
			},
			isBack: {
				type: Boolean,
				default: true
			},
		},

		methods: {
			goBack() {
				uni.navigateBack()
			}
		},
		created() {
			let self = this;
			uni.getSystemInfo({
				success: function(e) {
					self.statusBarH = (e.statusBarHeight + 10) * 1.8
					let custom = wx.getMenuButtonBoundingClientRect()
					self.customBarH = (custom.height + 10) * 1.8
				}
			})
		}
	}
</script>

<style scoped>
	.header {
		width: 100vw;
	}

	.flexbox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 10rpx;
	}

	.title {
		font-size: 30rpx;
	}
</style>